import 'package:flutter/material.dart';
import 'package:wayofdressing/all_widget/head_image.dart';

import '../screens/own_screen.dart';

class Message extends StatefulWidget {
  Message({
    required this.text,
    required this.isOpposite,
    required this.sentAt,
    required this.oppositeHeadImage,
    required this.id,
    required this.name,
  });

  final String text;
  final bool isOpposite;
  final DateTime sentAt;
  final ImageProvider oppositeHeadImage;
  int id = 0;
  String name = '';

  @override
  State<Message> createState() => _MessageState(
      text: text,
      isOpposite: isOpposite,
      sentAt: sentAt,
      oppositeHeadImage: oppositeHeadImage,
      id: id,
      name: name);
}

class _MessageState extends State<Message> {
  _MessageState({
    required this.text,
    required this.isOpposite,
    required this.sentAt,
    required this.oppositeHeadImage,
    required this.id,
    required this.name,
  });

  final String text;
  final bool isOpposite;
  final DateTime sentAt;
  final ImageProvider oppositeHeadImage;
  int id = 0;
  String name = '';

  @override
  Widget build(BuildContext context) {
    return widget.isOpposite
        ? Padding(
            padding: const EdgeInsets.only(left: 8.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    GestureDetector(
                      onTap: () {
                        Navigator.pushNamed(context, OwnScreen.id, arguments: {
                          'name': name,
                          'id': id,
                          'headImage': oppositeHeadImage
                        });
                      },
                      child: CircleAvatar(
                        backgroundImage: widget.oppositeHeadImage,
                        radius: 25,
                        backgroundColor: Colors.black,
                      ),
                    ),
                  ],
                ),
                Container(
                  margin: const EdgeInsets.only(
                      left: 5.0, right: 63, top: 15, bottom: 15),
                  padding:
                      EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  alignment: Alignment.topLeft,
                  decoration: const BoxDecoration(
                    borderRadius: BorderRadius.only(
                        bottomLeft: Radius.circular(25),
                        bottomRight: Radius.circular(25),
                        topRight: Radius.circular(25)),
                    color: Colors.white,
                  ),
                  child: ConstrainedBox(
                    constraints: BoxConstraints(
                        maxWidth: MediaQuery.of(context).size.width - 146),
                    child: Text(
                      widget.text,
                      softWrap: true,
                      style: const TextStyle(
                        color: Colors.black,
                        fontWeight: FontWeight.bold,
                        fontSize: 18.0,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          )
        : Padding(
            padding: const EdgeInsets.only(right: 8.0),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Container(
                  margin: const EdgeInsets.only(
                      left: 63, right: 5, top: 15, bottom: 15),
                  padding: const EdgeInsets.only(
                      left: 10, right: 10, top: 10, bottom: 10),
                  alignment: Alignment.topRight,
                  decoration: const BoxDecoration(
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(25),
                      bottomLeft: Radius.circular(25),
                      bottomRight: Radius.circular(25),
                    ),
                    color: Colors.blueAccent,
                  ),
                  child: ConstrainedBox(
                    constraints: BoxConstraints(
                        maxWidth: MediaQuery.of(context).size.width - 146),
                    child: Text(
                      widget.text,
                      softWrap: true,
                      style: const TextStyle(
                        color: Colors.white,
                        fontWeight: FontWeight.bold,
                        fontSize: 18.0,
                      ),
                    ),
                  ),
                ),
                Row(
                  children: [
                    GestureDetector(
                      onTap: (){
                        Navigator.pushNamed(context, OwnScreen.id, arguments: {
                          'name': name,
                          'id': id,
                          'headImage': oppositeHeadImage
                        });
                      },
                      child: CircleAvatar(
                        backgroundImage: headImage,
                        radius: 25,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          );
  }
}
